package com.ruoyi.web.controller.finance;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.finance.domain.FmsStaff;
import com.ruoyi.finance.service.IFmsStaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 员工 操作处理
 *
 * @author 夜雨
 */
@RestController
@RequestMapping("/finance/staff")
public class FmsStaffController extends BaseController
{
    @Autowired
    private IFmsStaffService staffService;

    /**
     * 获取员工列表
     */
    @PreAuthorize("@ss.hasPermi('finance:staff:list')")
    @GetMapping("/list")
    public TableDataInfo list(FmsStaff staff)
    {
        startPage();
        List<FmsStaff> list = staffService.selectStaffList(staff);
        return getDataTable(list);
    }

    /**
     * 根据员工编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('finance:staff:query')")
    @GetMapping(value = "/{staffId}")
    public AjaxResult getInfo(@PathVariable Long staffId)
    {
        return success(staffService.selectStaffById(staffId));
    }

    /**
     * 新增员工
     */
    @PreAuthorize("@ss.hasPermi('finance:staff:add')")
    @Log(title = "员工", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody FmsStaff staff)
    {
        staff.setCreateBy(getUsername());
        return toAjax(staffService.insertStaff(staff));
    }

    /**
     * 修改员工
     */
    @PreAuthorize("@ss.hasPermi('finance:staff:edit')")
    @Log(title = "员工", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody FmsStaff staff)
    {
        staff.setUpdateBy(getUsername());
        return toAjax(staffService.updateStaff(staff));
    }

    /**
     * 删除员工
     */
    @PreAuthorize("@ss.hasPermi('finance:staff:remove')")
    @Log(title = "员工", businessType = BusinessType.DELETE)
    @DeleteMapping("/{staffIds}")
    public AjaxResult remove(@PathVariable Long[] staffIds)
    {
        return toAjax(staffService.deleteStaffByIds(staffIds));
    }
}
